package com.hspedu.service.impl;

import com.hspedu.entity.Monster;
import com.hspedu.hspspringmvc.annotation.Service;
import com.hspedu.service.MonsterService;

import java.util.ArrayList;
import java.util.List;

/**
 * MonsterServiceImpl/对象 作为service注入到spring容器
 */
@Service
public class MonsterServiceImpl implements MonsterService {
    @Override
    public List<Monster> listMonster() {

        List<Monster> monsters =
                new ArrayList<>();
        monsters.add(new Monster(100, "牛魔王", "芭蕉扇", 400));
        monsters.add(new Monster(200, "老猫妖怪", "抓老鼠", 200));
        return monsters;
    }

    @Override
    public List<Monster> findMonsterByName(String name) {
        //模拟数据
        List<Monster> monsters =
                new ArrayList<>();
        monsters.add(new Monster(100, "牛魔王", "芭蕉扇", 400));
        monsters.add(new Monster(200, "老猫妖怪", "抓老鼠", 200));
        monsters.add(new Monster(300, "大象精", "运木头", 100));
        monsters.add(new Monster(400, "黄袍怪", "吐烟雾", 300));
        monsters.add(new Monster(500, "白骨精", "美人计", 800));


        //创建集合返回查询到的monster集合

        List<Monster> findMonsters =
                new ArrayList<>();
        //遍历monsters,返回满足条件
        for (Monster monster : monsters) {
            if (monster.getName().contains(name)) {
                findMonsters.add(monster);
            }
        }
        return findMonsters;
    }

    @Override
    public boolean login(String name) {
        //实际上会到DB验证->这里老师模拟
        if ("白骨精".equals(name)) {
            return true;
        } else {
            return false;
        }
    }
}
